package com.ruralflow.population.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruralflow.common.annotation.Log;
import com.ruralflow.common.core.controller.BaseController;
import com.ruralflow.common.core.domain.AjaxResult;
import com.ruralflow.common.enums.BusinessType;
import com.ruralflow.population.domain.Hukou;
import com.ruralflow.population.service.IHukouService;
import com.ruralflow.common.utils.poi.ExcelUtil;
import com.ruralflow.common.core.page.TableDataInfo;

/**
 * 户口信息Controller
 * 
 * @author ruralflow
 * @date 2025-02-15
 */
@RestController
@RequestMapping("/population/hukou")
public class HukouController extends BaseController
{
    @Autowired
    private IHukouService hukouService;

    /**
     * 查询户口信息列表
     */
    @PreAuthorize("@ss.hasPermi('population:hukou:list')")
    @GetMapping("/list")
    public TableDataInfo list(Hukou hukou)
    {
        startPage();
        List<Hukou> list = hukouService.selectHukouList(hukou);
        return getDataTable(list);
    }

    /**
     * 导出户口信息列表
     */
    @PreAuthorize("@ss.hasPermi('population:hukou:export')")
    @Log(title = "户口信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Hukou hukou)
    {
        List<Hukou> list = hukouService.selectHukouList(hukou);
        ExcelUtil<Hukou> util = new ExcelUtil<Hukou>(Hukou.class);
        util.exportExcel(response, list, "户口信息数据");
    }

    /**
     * 获取户口信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('population:hukou:query')")
    @GetMapping(value = "/{hukouId}")
    public AjaxResult getInfo(@PathVariable("hukouId") Long hukouId)
    {
        return success(hukouService.selectHukouByHukouId(hukouId));
    }

    /**
     * 新增户口信息
     */
    @PreAuthorize("@ss.hasPermi('population:hukou:add')")
    @Log(title = "户口信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Hukou hukou)
    {
        return toAjax(hukouService.insertHukou(hukou));
    }

    /**
     * 修改户口信息
     */
    @PreAuthorize("@ss.hasPermi('population:hukou:edit')")
    @Log(title = "户口信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Hukou hukou)
    {
        return toAjax(hukouService.updateHukou(hukou));
    }

    /**
     * 删除户口信息
     */
    @PreAuthorize("@ss.hasPermi('population:hukou:remove')")
    @Log(title = "户口信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hukouIds}")
    public AjaxResult remove(@PathVariable Long[] hukouIds)
    {
        return toAjax(hukouService.deleteHukouByHukouIds(hukouIds));
    }
}
